const host = 'https://192.168.31.156'
// const host = 'https://www.yhyoga.xyz'
const wxRequest = (params, url) => {
  console.log(url)
  wx.showLoading({
    title: '加载中……',
  })
  wx.request({
    url: url,
    method: params.method || 'GET',
    data: params.data || {},
    header: {
      'Content-Type': 'application/json'
    },
    success: (res) => {
      if (res.statusCode == 200) {
        wx.hideLoading()
        params.success && params.success(res.data)
      } else {
        wx.showModal({
          title: '请求异常',
          content: res.statusCode,
          showCancel: false
        })
      }
    },
    fail: (res) => {
      params.fail && params.fail(res)
    },
    complete: (res) => {
      params.complete && params.complete(res)
    }
  })
}

// Login
const login = (params) => wxRequest(params, host + '/api/login')
// Reg
const reg = (params) => wxRequest(params, host + '/api/reg')
// courses
const courses = (params) => wxRequest(params, host + '/api/courses')
// saveCourse
const saveCourse = (params) => wxRequest(params, host + '/api/saveCourse')
// updateCourse
const updateCourse = (params) => wxRequest(params, host + '/api/updateCourse')
// getCourse
const getCourse = (params) => wxRequest(params, host + '/api/getCourse')
// delCourse
const delCourse = (params) => wxRequest(params, host + '/api/delCourse')
// upUserConf
const upUserConf = (params) => wxRequest(params, host + '/api/upUserConf')

module.exports = {
  login,
  reg,
  courses,
  saveCourse,
  updateCourse,
  getCourse,
  delCourse,
  upUserConf
}